package com.ag.dgm.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;


import com.ag.bean.TbPlanStatus;
import com.ag.common.BaseAction;
import com.ag.common.IDUtil;
import com.ag.dgm.service.PlanStatusService;


@Controller("PlanStatusAction")
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class PlanStatusAction extends BaseAction {
	private static final long serialVersionUID = 5103174835055423792L;

	@Resource(name="planStatusService")
	private PlanStatusService planStatusService;
	private List<TbPlanStatus> tbPlanStatusList;
	private String Id;
	private String Name;
	
	private String result;
	TbPlanStatus tbPlanStatus = new TbPlanStatus();



	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}



	public void setTbPlanStatusList(List<TbPlanStatus> tbPlanStatusList) {
		this.tbPlanStatusList = tbPlanStatusList;
	}


	public List<TbPlanStatus> getTbPlanStatusList() {
		return tbPlanStatusList;
	}

	public String getId() {
		return Id;
	}

	public void setId(String Id) {
		this.Id = Id;
	}

	public String getName() {
		return Name;
	}

	public void setName(String Name) {
		this.Name = Name;
	}


	public String find() {
		tbPlanStatusList = planStatusService.findAll();
		return "main";
	}

	public String modify() {
		tbPlanStatus.setPstId(Id);

		tbPlanStatus.setPstName(Name);
		this.setResult("修改成功");
		try {
			planStatusService.modify(tbPlanStatus);
		} catch (Exception e) {
			this.setResult("修改不成功");
		}
		return "modify_succ";
		
	}

	public String delete() {
		tbPlanStatus.setPstId(Id);
		this.setResult("删除成功");
	
			try {
				planStatusService.delete(tbPlanStatus);
			} catch (Exception e) {
				e.printStackTrace();
			}
		return "delete_succ";
	}

	public String add() {

		tbPlanStatus.setPstName(Name);
		tbPlanStatus.setA(IDUtil.PRESERVE);
		this.setResult("增加成功");
		try {
			planStatusService.add(tbPlanStatus);
		} catch (Exception e) {
			this.setResult("增加不成功");
		}
		return "add_succ";	
	}

}
